<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    /* 
      https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/
      思路：https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/solution/fu-zhu-zhan-by-qing-jiao-wo-xiao-bai-tong-xue/
     */
    function validateStackSequences(pushed, popped) {
      const stack = []
      let index = 0

      for (let i = 0; i < pushed.length; i++) {
        stack.push(pushed[i])
        while (stack.length && stack[stack.length-1] === popped[index]) {
          stack.pop()
          index++
        }
      }

      return stack.length === 0
    }
  </script>
</body>
</html>